package com.study.javaOther.dailytest;

import com.alibaba.fastjson.JSON;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.io.ByteArrayInputStream;
import java.util.concurrent.TimeUnit;

@State(Scope.Benchmark)
public class InputStreamTest {
    static String[][] testData = buildDoubleArray(200000, 200);

    private static String[][] buildDoubleArray(int i, int i1) {
        String[][] data=new String[i][i1];
        for (int i2 = 0; i2 < i; i2++) {
            for (int i3 = 0; i3 < i1; i3++) {
                data[i2][i3]="test:"+i2+i3;
            }
        }
        System.out.println("生成完成");
        return data;
    }

    @TearDown(Level.Trial)
    public void tearDown(){
        System.out.println("TearDown");
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .warmupIterations(3)
                .measurementIterations(5)
                .timeUnit(TimeUnit.MILLISECONDS)
                .forks(1)
                .mode(Mode.SampleTime)
                .include(InputStreamTest.class.getSimpleName())
                .build();
        new Runner(opt).run();
    }
    @Benchmark
    public void testJSONString() {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(JSON.toJSONString(testData).getBytes());
    }

    @Benchmark
    public void test12000() {

    }
}
